<?php
session_start();
require_once '../header.php';
function __autoload($className)
	{
    	require_once('../class/' . $className . '.class.php');
	}
session::need_manage();
if(!empty($_GET))
{
	$Year=$_GET["year"];
	$Month=$_GET["month"];
	$Day=$_GET["day"];
	if(strlen($Month)==1)
	{
		$Month="0".$Month;
	}
	if(strlen($Day)==1)
	{
		$Day="0".$Day;
	}
	
	$date="$Year-$Month-$Day";
	$condition[] = "timeorder like '%".mysql_escape_string($date)."%'";
	$GetCountSell=database::LimitQuery('ccinfo',array(
	'select' => 'count(*)',
	'condition' => $condition,
	)
	);
	$GetSite=database::LimitQuery('ccinfo',array(
	'select' => 'DISTINCT site',
	'condition' => $condition
	));
	$i=0;
	if(empty($GetSite))
	{
		echo "Can Not Find Data";
	}
	
	else
	{
	foreach($GetSite as $Site)
	{
		$condition[] = "timeorder like '%".mysql_escape_string($date)."%'";
		$SiteCc=$Site['site'];
		$condition['site']=$SiteCc;
		$GetCountry=database::LimitQuery('ccinfo',array(
		'select' => 'DISTINCT country',
		'condition' => $condition
		));
		foreach($GetCountry as $ShowCountry)
		{
			
			$Country[$SiteCc][]=$ShowCountry['country'];
		}
		
		$ii=array(
		'country' => $Country[$SiteCc]
		);
		unset($build);
		$build=database::BuildCondition($ii);
		
		$condition[]=$build;
		
		$CountSell=database::LimitQuery('ccinfo',array(
		'select'=> 'country,count(*)',
		'condition' => $condition,
		'groupby' => 'group by country'
		
		));
		$condition['status']='INVALID';
		$CountDie=database::LimitQuery('ccinfo',array(
		'select'=> 'country,count(*)',
		'condition' => $condition,
		'groupby' => 'group by country'
		
		));
		unset($condition);
		$Report[$i]['sitecc']=$SiteCc;
		foreach($CountSell as $Country)
		{
			$Report[$i][$SiteCc]['country'][]=$Country['country'];
			$Report[$i][$SiteCc]['sell'][]=$Country['count(*)'];
		}
		foreach($CountDie as $Country)
		{
			$Report[$i][$SiteCc]['die'][]=$Country['count(*)'];
		}
		$i++;
	}
	require_once '../html/report.php';
	}
	
}
else 
{
	require_once '../html/setreport.php';
}

?>